package se.perp.c4.ui;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import se.perp.c4.control.iface.ICardClickListener;
import se.perp.c4.model.Card;

/**
 * An ImagePanel that is coupled with a Card.
 * @author Per P
 */
public class CardImagePanel extends ImagePanel implements MouseListener {

    private Card card;
    private ICardClickListener callback = null;

    /**
     * Creates a new instance. 
     * @param card The card we couple to the imagecomponent.
     */
    public CardImagePanel(Card card) {
        super(Images.getCardImage(card));
        this.card = card;
        setToolTipText("<html><body><center><b>"+card.name+"</b></center>"+card.text+"</body></html>");
        addMouseListener(this);
    }

    public Card getCard() {
        return card;
    }

    public void setClickListener(ICardClickListener l) {
        callback = l;
    }

    @Override
    public void mouseClicked(MouseEvent e) {
        if (e.getClickCount() == 2 && callback != null) {
            callback.cardPicked(card);
        }
    }
  
}
